﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//using TestDLLDependent;
using Reflector;
using Reflector.CodeModel;
using System.Collections;

namespace TestDLL
{

    public class MultipleTestDomainRunner 
    {
        #region Constructors
        public MultipleTestDomainRunner() { }
        ArrayList runners;
        HashSet<MultipleTestDomainRunner> assemblies;
        String TestName;
        String targetAssemblyName;
        #endregion

        ArrayList arrayList = new ArrayList();
        public ArrayList list
        {
            get
            {
                return arrayList;
            }
        }

        #region Load Method Overrides
        /*public void Load(String [] input)
        {
            runners = new ArrayList();

            int nfound = 0;
            int index = 0;

            foreach (string assembly in input)
            {
                if (targetAssemblyName == null || targetAssemblyName == assembly)
                {
                    foreach (object key in assemblies)
                    {
                        Console.WriteLine("test");
                    }

                    if (TestName == null)
                    {
                        runners.Add(assembly);
                        
                    }
                    else if (true)
                    {
                        runners.Add(assembly);
                        
                    }
                }
            }

        }*/

        private void CreateRunners_First(int count)
        {
            runners = new ArrayList();
            runners.Capacity = 10;
            runners.Add("test");
            
            HashSet<ArrayList> hsObj = new HashSet<ArrayList>();
            hsObj.Add(this.list);
            hsObj.Add(runners);

            /*runners = new ArrayList();

            assemblies = new HashSet<MultipleTestDomainRunner>();
            for (int index1 = 0; index1 < count; index1++)
            {
                for (int index2 = 0; index2 < count; index2++)
                    assemblies.Add(new MultipleTestDomainRunner());
            }*/
        }

        /*private void CreateRunners(int count)
        {
            runners = new ArrayList();
            for (int index = 0; index < count; index++)
            {
                runners.Add("1");
            }

            assemblies = new HashSet<MultipleTestDomainRunner>();
            for (int index1 = 0; index1 < count; index1++)
            {
                for (int index2 = 0; index2 < count; index2++ ) 
                    assemblies.Add(new MultipleTestDomainRunner());
            }
        }*/

        /*private void CreateRunners1(int count)
        {
            runners = new ArrayList();
            //for (int index = 0; index < count; index++)
            //{
            runners.Add("1");
            runners.Add("2");
            //}

            HashSet<String> assemblies = new HashSet<String>();
            //for (int index = 0; index < count; index++)
            //{
            assemblies.Add("1");
            assemblies.Add("2");
            //}
        }*/
        #endregion
    }


    /*public class Class1
    {
        //Reflector code
        public static void Main()
        {
            IServiceProvider serviceProvider = new ApplicationManager(null);

            IAssemblyManager assemblyManager = (IAssemblyManager)serviceProvider.GetService(typeof(IAssemblyManager));

            IAssembly assembly = assemblyManager.LoadFile("test.dll");

            Console.WriteLine("Assembly: " + assembly.ToString());

            foreach (IModule module in assembly.Modules)
            {
                Console.WriteLine("Module: " + module.Name);

                foreach (ITypeDeclaration typeDeclaration in module.Types)
                {
                    Console.WriteLine("Type: " + typeDeclaration.Namespace + "." + typeDeclaration.Name);

                    foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Methods)
                    {
                        Console.WriteLine("Method: " + methodDeclaration);

                        IMethodBody methodBody = methodDeclaration.Body as IMethodBody;
                        if (methodBody != null)
                        {
                            foreach (IInstruction instruction in methodBody.Instructions)
                            {
                                Console.WriteLine();
                            }
                        }
                    }
                }
            }

            assemblyManager.Unload(assembly);
        }    

        public void testMe(FileStream file)
        {            
            file.BeginWrite(new byte[10], 10, 10, null, null);
            if (file.CanWrite)
            {
                bool bField = file.CanWrite;
                Console.WriteLine("This should not occur");
                StreamWriter sw = new StreamWriter(file);
                //StreamWriter sw1 = new StreamWriter(file);
                sw.Write("Hello file system world!");
                sw.Close();
            }

            //StreamWriter sw1 = getStreamWriter();
            Console.WriteLine("Hello World!!!");
        }

        public void testMeSub()
        {
            ClassDependent cdObj = new ClassDependent();            
            String path = "path.txt";
            FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write);
            //testMe(file);
        }

        public void testMeSub2()
        {
            String path = "path.txt";
            FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write);
            testMe(file);
        }

        public Class1()
        {
            Console.WriteLine("This is my constructor");
        }

        public StreamWriter getStreamWriter()
        {            
            return null;
        }

        public void anotherSequenceFunc()
        {
            int i = 0;
            StreamWriter sw = null;
            MemoryStream mstm = null;
            //if (i > 0)
            //{
                while (i > 300)
                {
                    i++;

                    if (i < 100)
                    {
                        Console.WriteLine("To test");
                    }
                    else
                    {
                        Console.WriteLine("To test new");
                    }
                    mstm = new MemoryStream();
                }

                sw = new StreamWriter(mstm);
                Console.WriteLine("This should not occur");              

                //sw = new StreamWriter(mstm);
                //sw.Write("");
                //sw.Flush();
                //mstm.Seek(0, SeekOrigin.Begin);
                //sw.Close();
            //}
            //else
            //{
            //   sw = File.CreateText("test.txt");
            //}           
        }
    }*/
}
